package com.comet.config;

import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
import java.util.Arrays;
import java.util.Collection;

/**
 * 标准分表策略Range
 */
public class TableRangeShardingAlgorithm implements RangeShardingAlgorithm<Long> {
    @Override
    public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {

        // select * from order where order_id between 100 and 200

        // 上限
        Long upperEndpoint = rangeShardingValue.getValueRange().upperEndpoint();
        // 下限
        Long lowerEndpoint = rangeShardingValue.getValueRange().lowerEndpoint();
        // 分片键
        String columnName = rangeShardingValue.getColumnName();
        // 逻辑表
        String logicTableName = rangeShardingValue.getLogicTableName();

        return Arrays.asList(logicTableName + "_1",logicTableName + "_2");
    }
}
